<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单图轮播图</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f0f0;
        }

        .carousel-container {
            position: relative;
            width: 800px;
            height: 400px;
            overflow: visible;
        }

        .carousel-item {
            position: absolute;
            width: 100%;
            height: 100%;
            background: white;
            border-radius: 10px;
            overflow: hidden;
            transition: all 0.5s ease;
            opacity: 0;
            transform: translateX(100%);
            cursor: pointer;
        }

        .carousel-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .carousel-item.active {
            opacity: 1;
            transform: translateX(0);
            z-index: 3;
        }

        .carousel-item.next {
            opacity: 0.3;
            transform: translateX(20px);
            z-index: 2;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
        }

        .carousel-item.next2 {
            opacity: 0.2;
            transform: translateX(40px);
            z-index: 1;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
        }

        .carousel-controls {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            gap: 10px;
            z-index: 4;
        }

        .carousel-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.5);
            cursor: pointer;
            transition: background 0.3s ease;
        }

        .carousel-dot.active {
            background: white;
        }

        .carousel-arrow {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            font-size: 20px;
            color: #333;
            transition: background 0.3s ease;
            z-index: 4;
        }

        .carousel-arrow:hover {
            background: white;
        }

        .carousel-arrow.prev {
            left: -60px;
        }

        .carousel-arrow.next {
            right: -60px;
        }
    </style>
</head>
<body>
    <div class="carousel-container">
        <div class="carousel-item active">
            <img src="https://picsum.photos/800/400?random=1" alt="图片1">
        </div>
        <div class="carousel-item">
            <img src="https://picsum.photos/800/400?random=2" alt="图片2">
        </div>
        <div class="carousel-item">
            <img src="https://picsum.photos/800/400?random=3" alt="图片3">
        </div>
        <div class="carousel-item">
            <img src="https://picsum.photos/800/400?random=4" alt="图片4">
        </div>
        <div class="carousel-item">
            <img src="https://picsum.photos/800/400?random=5" alt="图片5">
        </div>

        <div class="carousel-controls">
            <div class="carousel-dot active"></div>
            <div class="carousel-dot"></div>
            <div class="carousel-dot"></div>
            <div class="carousel-dot"></div>
            <div class="carousel-dot"></div>
        </div>

        <div class="carousel-arrow prev">❮</div>
        <div class="carousel-arrow next">❯</div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const container = document.querySelector('.carousel-container');
            const items = document.querySelectorAll('.carousel-item');
            const dots = document.querySelectorAll('.carousel-dot');
            const prevBtn = document.querySelector('.carousel-arrow.prev');
            const nextBtn = document.querySelector('.carousel-arrow.next');
            
            let currentIndex = 0;
            const totalItems = items.length;

            function updateCarousel() {
                items.forEach((item, index) => {
                    item.classList.remove('active', 'next', 'next2');
                    if (index === currentIndex) {
                        item.classList.add('active');
                    } else if (index === (currentIndex + 1) % totalItems) {
                        item.classList.add('next');
                    } else if (index === (currentIndex + 2) % totalItems) {
                        item.classList.add('next2');
                    }
                });

                dots.forEach((dot, index) => {
                    dot.classList.toggle('active', index === currentIndex);
                });
            }

            function nextSlide() {
                currentIndex = (currentIndex + 1) % totalItems;
                updateCarousel();
            }

            function prevSlide() {
                currentIndex = (currentIndex - 1 + totalItems) % totalItems;
                updateCarousel();
            }

            // 点击事件
            nextBtn.addEventListener('click', nextSlide);
            prevBtn.addEventListener('click', prevSlide);

            // 点击右侧阴影区域翻页
            items.forEach((item, index) => {
                item.addEventListener('click', (e) => {
                    const rect = item.getBoundingClientRect();
                    const clickX = e.clientX - rect.left;
                    const threshold = rect.width * 0.7; // 右侧30%区域触发翻页
                    
                    if (clickX > threshold && (item.classList.contains('next') || 
                        item.classList.contains('next2'))) {
                        nextSlide();
                    }
                });
            });

            dots.forEach((dot, index) => {
                dot.addEventListener('click', () => {
                    currentIndex = index;
                    updateCarousel();
                });
            });
        });
    </script>
</body>
</html> 